#ifndef BAIDULPR_H
#define BAIDULPR_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>

#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonArray>
#include <QHostInfo>

#include <QFile>
#include <QImage>
class BaiduLPR : public QObject
{
    Q_OBJECT
public:
    explicit BaiduLPR(QObject *parent = nullptr);

    /* 发送请求 */
    void requestNetwork(QString, QByteArray);

private:
    /* 管理器 */
    QNetworkAccessManager *networkAccessManager;

    /* 自己的token码 */
    QString MytokenUrl;

    /* 最后访问百度AI车牌的Url */
    QString serverApiUrl;

    /* 最后访问百度AI口罩检测的Url */
    QString serverApiUrl2;

    /* 最后获取车牌token */
    QString GettokneUrl;

    /* 口罩token */
    QString masktokenUrl;

    /* 获取token的Url */
    const QString GettokenApi = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%1&client_secret=%2";

    /* 自己的Apikey */
    const QString MyApiKey = "odQ7CAPDAzFsMOvdMDP3pega";

    /* 自己的SecretKey */
    const QString MySecretKey = "XnkWKRIWbR1Exye6F397VT7I5ny3proG";

    /* 车牌百度AI的接口 */
    const QString BaiduLPRApi = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token=%1";

    /* 口罩百度AI的接口*/
    const QString BaiduMaskApi = "https://aip.baidubce.com/rest/2.0/image-classify/v1/body_attr?access_token=%1";

    const QString TmpCMD = "tmp_ready";

    QString getJsonValue(QByteArray ba, QString key);
    QString getJsonValue(QByteArray ba, QString key1, QString key2);
    QString GetMaskValue(QByteArray ba);
signals:
    void GetLRPData(QString);
    void seedsqldata(QString);
    void CarIDTTS(QString);
    void TmpReady(QString);
    void TTS_CMD(QString);
public slots:
    void ready2OCR(QString imagePath);
    void rlyFinished();
    void readyReadData();
    void GetOCRResult(QString filename);
    void GetMaskResult(QString filename);
};

#endif // BAIDULPR_H
